def f(x):
    for i in range(2, int(x**0.5)+1):
        if x % i == 0:
            return False
    return True
    
c = ''
wrong = 0
for i in input().split():
    if i == "zero":
        c += '0'
    elif i == "one":
        c += '1'
    elif i == "two":
        c += '2'
    elif i == "three":
        c += '3'
    elif i == "four":
        c += '4'
    elif i == "five":
        c += '5'
    elif i == "six":
        c += '6'
    elif i == "seven":
        c += '7'
    elif i == "eight":
        c += '8'
    elif i == "nine":
        c += '9'
    else:
        wrong = 1
        break
    
if wrong == 1 or len(c) != 3:
    print("Wrong input")
else:
    c = int(c)

    nmin = 0
    nmax = 0
    
    for i in range(c+1, 1000):
        if f(i):
            nmax = i
            break
        
    for i in range(c-1, 99, -1):
        if f(i):
            nmin = i
            break
    
    if c-nmin > nmax-c:
        print(nmax)
    else:
        print(nmin)
